<?php

namespace mpend\modules\user\controllers;

use Yii;
use mpend\components\Controller;
use mpend\modules\user\models\ProfileForm;
use mpend\modules\user\models\ProfileSearch;

/**
 * 个人资料相关功能
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class ProfileController extends Controller {

    /**
     * @inheritdoc
     */
    protected function rules() {
        return [
            [
                'allow' => true,
                'roles' => ['@'],
            ],
        ];
    }

    /**
     * @inheritdoc
     */
    public function actionIndex() {
        $model = new ProfileSearch();
        $model->id = $this->uid;
        $model->load(Yii::$app->request->getQueryParams(), '');
        return $model->searchOne();
    }

    /**
     * @inheritdoc
     */
    public function actionUpdate() {
        $model = new ProfileForm();
        $model->id = $this->uid;
        if (!$model->load(Yii::$app->request->post(), '')) {
            parent::error('请提交要完善信息');
        }
        return $model->save();
    }

}
